/**
 * @param {number[]} nums
 * @return {boolean}
 */
var canJump = function (nums) {
    if (nums.length === 1)
        return true
    let start = 0
    let end = start + nums[start]
    while (true) {
        if (nums[start] === 0) {
            return false
        }
          if(nums[start]>=nums.length-1){
            return true
        }
        let value = Math.max(...nums.slice(start+1, end + 1))
        console.log('value:',value)
        if (value === 0) {
            return false
        }
        let max = nums.slice(start+1, end + 1).indexOf(value)
        start = max
        end = start + nums[start]
        if (end >= nums.length - 1) {
            return true
        }
        if (nums[end] === 0) {
            return false
        }
    }
};

canJump([1,1,0,1])